﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HammerMUD.Commands;
using HammerMUD.System;
using HammerMUD.Rooms;

namespace HammerMUD.Admin
{
    public class LinkCommand : Command
    {
        public LinkCommand()
        {
            Name = "link";
            Help = "link <room number> <room number> <east/west/south/north/custom>";
        }

        public override void Do(User from, List<string> arguments)
        {
            if (arguments.Count < 4)
            {
                from.Send(Help);
                return;
            }

            Exit theExit = new Exit();
            Exit reciprocalExit = new Exit();
            theExit.From = Int64.Parse(arguments[1]);
            theExit.To = Int64.Parse(arguments[2]);
            reciprocalExit.From = theExit.To;
            reciprocalExit.To = theExit.From;

            if (NormalExit.East.Contains(arguments[3]))
            {
                theExit.Names = NormalExit.East.ToList();
                reciprocalExit.Names = NormalExit.West.ToList();
            }
            else if (NormalExit.West.Contains(arguments[3]))
            {
                theExit.Names = NormalExit.West.ToList();
                reciprocalExit.Names = NormalExit.East.ToList();
            }
            else if (NormalExit.South.Contains(arguments[3]))
            {
                theExit.Names = NormalExit.South.ToList();
                reciprocalExit.Names = NormalExit.North.ToList();
            }
            else if (NormalExit.North.Contains(arguments[3]))
            {
                theExit.Names = NormalExit.North.ToList();
                reciprocalExit.Names = NormalExit.South.ToList();
            }
            else
            {
                theExit.Names.Add(arguments[3]);
                reciprocalExit.Names.Add(arguments[3]);
            }

            RoomUtilities.FindRoom(theExit.From).Exits.Add(theExit);
            RoomUtilities.FindRoom(theExit.To).Exits.Add(reciprocalExit);
        }
    }
}
